// pages/physical-detail/physical-detail.js
Page({
	data: {
		patientName: '',
		packageName: '',
		packagePrice: '',
		reportDate: '',
		bookingDate: '',
		patientId: '610*********0989'
	},

	onLoad(options) {
		console.log('体检预约详情页面加载')
		console.log('页面参数:', options)
		
		if (options.patient) {
			this.setData({
				patientName: options.patient
			})
		}
		
		if (options.package) {
			try {
				const packageData = JSON.parse(options.package)
				this.setData({
					packageName: packageData.name,
					packagePrice: packageData.price
				})
			} catch (e) {
				console.error('解析套餐数据失败:', e)
			}
		}
		
		// 设置日期
		this.setDates(options.date)
	},

	// 设置日期
	setDates(appointmentDate) {
		const today = new Date()
		const bookingDate = today.toLocaleDateString('zh-CN', {
			year: 'numeric',
			month: '2-digit',
			day: '2-digit'
		}).replace(/\//g, '-')
		
		// 报道时间设置为预约日期
		const reportDate = appointmentDate ? this.formatDate(appointmentDate) : '2025-01-03'
		
		this.setData({
			reportDate: reportDate,
			bookingDate: bookingDate
		})
	},

	// 格式化日期
	formatDate(dateString) {
		const date = new Date(dateString)
		return date.toLocaleDateString('zh-CN', {
			year: 'numeric',
			month: '2-digit',
			day: '2-digit'
		}).replace(/\//g, '-')
	}
})
